package Z.dailyExercise.holiday;

public class _744_寻找比目标字母大的最小字母 {
    //存在连续等的情况
    public char nextGreatestLetter(char[] letters, char target) {
        if (target < letters[0] || target >= letters[letters.length-1]) {
            return letters[0];
        }
        int low =0;
        int high = letters.length-1;

        while (low<high){

            int mid = low+(high-low)/2;
            if (letters[mid]>target){
                high = mid-1;
            }else if (letters[mid]<target){
                if (letters[mid+1]>target){
                    return letters[mid+1];
                }else {
                    low = mid+1;
                }

            }else {
                low = mid+1;
            }
        }

        //陷入循环

        //if是指 cfj中target为d
        //else则是eeeeeeennnn中target为e
        if(letters[low] <= target){
            return letters[low+1];
        }else {
            return letters[low];
        }


    }

}
